package com.pennywise.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 统一日志处理切面
 */
@Slf4j
@Aspect
@Component
public class LogAspect {
    
    @Around("execution(* com.pennywise.service.*.*(..))")
    public Object logServiceMethod(ProceedingJoinPoint joinPoint) throws Throwable {
        String methodName = joinPoint.getSignature().getName();
        String className = joinPoint.getTarget().getClass().getSimpleName();
        
        log.debug("开始执行 {}.{}", className, methodName);
        long startTime = System.currentTimeMillis();
        
        try {
            Object result = joinPoint.proceed();
            log.debug("{}.{} 执行完成，耗时：{}ms", className, methodName, 
                    System.currentTimeMillis() - startTime);
            return result;
        } catch (Throwable e) {
            log.error("{}.{} 执行异常", className, methodName, e);
            throw e;
        }
    }
} 